package com.hiyee.platform.exception;

import com.hiyee.platform.response.ResponseJsonResult;
import com.hiyee.platform.response.ResponseStatusEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

/**
 * 统一异常拦截处理
 * 返回 json 到前端
 *
 * @author WangBin
 */
@ControllerAdvice
public class GraceExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public ResponseJsonResult returnBusinessException(BusinessException e) {
        e.printStackTrace();
        return ResponseJsonResult.error(e.getResponseStatusEnum().getMsg());
    }

    @ExceptionHandler(MaxUploadSizeExceededException.class)
    @ResponseBody
    public ResponseJsonResult returnBusinessException(MaxUploadSizeExceededException e) {
        e.printStackTrace();
        return ResponseJsonResult.error(ResponseStatusEnum.UPLOAD_FILE_SIZE_LIMIT);
    }

}
